﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using Newtonsoft.Json;

public partial class Bk : Basic
{
    public string code = "002069";
    public string bkName = "";
    public string strHyGgPh = "";  //行业个股排行
    public string strPFPH = "";  //评分排行
    public string strGzgp = "";  //可关注股票
    public string strHyfx = "";  //行业分析
    public string strZshq = "";  //指数行情
    public string strWpzy = "";  //操盘摘要
    public string strHyxw = "";  //行业新闻
    public string strHyyj = "";  //行业研究
    public string strZbfx = "";  //指标分析
    public int cTime = 10;  //当前几点钟

    protected void Page_Load(object sender, EventArgs e)
    {
        code = OTO.ToStr(Request["code"], "002069");
        cTime = DateTime.Now.Hour;
        if (OTO.IsSCode(code) == false)
        {
            Response.Write("<script>alert(\"请不要进行非法操作！\");this.location.href='/';</script>");
            Response.End();
        }

        strGzgp = sb可关注股票(code, out bkName).ToString();
        strHyGgPh = sb行业个股排行(code).ToString();
        strPFPH = sb评分排行(code).ToString();
        strHyfx = sb行业分析(code).ToString();
        strZshq = sb指数行情().ToString();
        strWpzy = str操盘摘要(code);
        strHyxw = sb行业新闻(code).ToString();
        strHyyj = sb行业研究(code).ToString();
        strZbfx = sb指标分析(code).ToString();

        _title = bkName + "板块-股票行情中心-益盟操盘手";
        _keywords = "板块行情，行业分析，新闻资讯,益盟操盘手,操盘手软件-益盟操盘手";
        _desc = "益盟操盘手行情中心独家提供及时而准确的行业板块行情，板块分析，可关注股票等全方位行业板块信息，为投资提供参考决策。";
        BasicHeader(_title, string.Empty, string.Empty, _desc, _keywords);
    }

    protected StringBuilder sb行业个股排行(string code)
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            List<BkPhEnty> list = JsonConvert.DeserializeObject<List<BkPhEnty>>(Pub.LoadData(jsonUrl + "hangqing/Hyggph.ashx?code=" + code));

            sb.AppendLine("<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\">");
            sb.AppendLine("  <tr class=\"tableSmall1Head\">");
            sb.AppendLine("    <td class=\"gray\">股票名称</td>");
            sb.AppendLine("    <td class=\"gray\">涨跌幅</td>");
            sb.AppendLine("    <td class=\"gray\" width=\"58\" align=\"center\">操盘线</td>");
            sb.AppendLine("  </tr>");
            int i = 0;
            list = list.Take(10).ToList();
            foreach (var m in list)
            {
                i++;
                string _class = " class=\"bgGray\"";
                if (i % 2 == 0)
                    _class = "";
                sb.AppendFormat("  <tr {0}>", _class);
                sb.AppendFormat("    <td><a href=\"Gg{1}.shtml\" class=\"b\">{0}</a></td>", m.N, m.C);
                sb.AppendFormat("    <td class=\"red\">{0}</td>", OTO.PerRedGre(m.F, 1, 2, "-", "%"));
                sb.AppendFormat("    <td class=\"{1}\" align=\"center\" title=\"{2}\">{0}</td>", Math.Abs(m.NC), m.NC < 0 ? "bg_tipG" : "bg_tipR", Pub.NcTip(m.NC));
                sb.AppendLine("  </tr>");
            }
            sb.AppendLine("</table>");
        }
        catch
        {
            sb = new StringBuilder();
        }
        return sb;
    }

    protected StringBuilder sb评分排行(string code)
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            List<BkPhEnty> list = JsonConvert.DeserializeObject<List<BkPhEnty>>(Pub.LoadData(jsonUrl + "hangqing/pfph.ashx?bkid=" + code));

            sb.AppendLine("<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\">");
            sb.AppendLine("  <tr class=\"tableSmall1Head\">");
            sb.AppendLine("    <td class=\"gray\">股票名称</td>");
            sb.AppendLine("    <td class=\"gray\">涨跌幅</td>");
            sb.AppendLine("    <td class=\"gray\" width=\"58\" align=\"center\">操盘线</td>");
            sb.AppendLine("  </tr>");
            int i = 0;
            list = list.Take(10).ToList();
            foreach (var m in list)
            {
                i++;
                string _class = " class=\"bgGray\"";
                if (i % 2 == 0)
                    _class = "";
                sb.AppendFormat("  <tr {0}>", _class);
                sb.AppendFormat("    <td><a href=\"Gg{1}.shtml\" class=\"b\">{0}</a></td>", m.N, m.C);
                sb.AppendFormat("    <td class=\"red\">{0}</td>", OTO.PerRedGre(m.F, 1, 2, "-", "%"));
                sb.AppendFormat("    <td class=\"{1}\" align=\"center\" title=\"{2}\">{0}</td>", Math.Abs(m.NC), m.NC < 0 ? "bg_tipG" : "bg_tipR",Pub.NcTip(m.NC));
                sb.AppendLine("  </tr>");
            }
            sb.AppendLine("</table>");
        }
        catch
        {
            sb = new StringBuilder();
        }
        return sb;
    }

    protected StringBuilder sb可关注股票(string code, out string bkName)
    {
        StringBuilder sb = new StringBuilder();
        bkName = "";
        try
        {
            KgzgpEnty obj = JsonConvert.DeserializeObject<KgzgpEnty>(Pub.LoadData(jsonUrl + "hangqing/hykgzgp.ashx?bkid=" + code));

            if (obj != null)
            {
                bkName = obj.bkmc;
                List<KgzgpItemEnty> list = obj.lst;
                int len = 4;
                if (list.Count < 4)
                    len = list.Count;
                for (int i = 0; i < len; i++)
                {
                    sb.AppendLine("<ul kgzgp=\"kgzgp_ul\">");
                    sb.AppendLine("<li class=\"sjgp_1\" style=\"text-align:left;\"><img src=\"images/report_ico2.jpg\" /></li>");
                    sb.AppendFormat("<li class=\"sjgp_2 bottom_line\"><a href=\"Gg{1}.shtml\">{0}</a></li>", list[i].name, list[i].stockid);
                    sb.AppendFormat("<li class=\"sjgp_2 bottom_line\">{0}</li>", OTO.PerRedGre(list[i].P,list[i].F,1,2,"-",""));
                    sb.AppendFormat("<li class=\"sjgp_2 bottom_line\">{0}</li>", OTO.PerRedGre(list[i].F,2,"-","%"));
                    sb.AppendLine("</ul>");
                    sb.AppendFormat("<div class=\"sjgp_m report_bg hide\" kgzgp=\"kgzgp_c\">{0}</div>", OTO.CutStr(list[i].reason,45));
                }
            }
        }
        catch
        { }
        return sb;
    }

    protected StringBuilder sb行业分析(string code)
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            HyfxEnty obj = JsonConvert.DeserializeObject<HyfxEnty>(Pub.LoadData(jsonUrl + "hangqing/tzyd.ashx?bkid=" + code));
            if (obj != null)
            {
                sb.AppendLine("<ul>");
                sb.AppendLine("  <li>");
                sb.AppendLine("    <div class=\"bk_ly_l2_r1_t blue font-weight\">投资要点</div>");
                sb.AppendFormat("    <div class=\"bk_ly_l2_r1_c\">{0}</div>", obj.tzyd);
                sb.AppendLine("  </li>");
                sb.AppendLine("  <li>");
                sb.AppendLine("    <div class=\"bk_ly_l2_r1_t blue font-weight\">行业新闻</div>");
                sb.AppendFormat("    <div class=\"bk_ly_l2_r1_c\">{0}</div>", obj.hyxw);
                sb.AppendLine("  </li>");
                sb.AppendLine("  <li>");
                sb.AppendLine("    <div class=\"bk_ly_l2_r1_t blue font-weight\">行业现状</div>");
                sb.AppendFormat("    <div class=\"bk_ly_l2_r1_c\">{0}</div>", obj.hyxz);
                sb.AppendLine("  </li>");
                sb.AppendLine("  <div class=\"clearok\"></div>");
                sb.AppendLine("  <li class=\"download\"><img src=\"images/ico_download.jpg\" />更多行业分析数据可 <a href=\"http://down.emoney.cn/wl0401282.exe\" class=\"b\">免费下载行情版</a>&nbsp;</li>");
                sb.AppendLine("</ul>");
            }
        }
        catch
        {
            sb = new StringBuilder();
        }
        return sb;
    }

    protected StringBuilder sb指数行情()
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            List<ZshqEnty> list = JsonConvert.DeserializeObject<List<ZshqEnty>>(Pub.LoadData(jsonUrl + "hangqing/hyzyzslb.ashx"));
            sb.AppendLine("<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\">");
            sb.AppendLine("  <tr class=\"tableSmall1Head gray\">");
            sb.AppendLine("	<td>A股市场</td>");
            sb.AppendLine("	<td>最新</td>");
            sb.AppendLine("	<td>涨跌幅</td>");
            sb.AppendLine("	<td>主力净买</td>");
            sb.AppendLine("	<td>股票数量</td>");
            sb.AppendLine("	<td>涨跌家数</td>");
            sb.AppendLine("	<td width=\"58\" align=\"center\">操盘线</td>");
            sb.AppendLine("  </tr>");
            for (int i = 0; i < list.Count; i++)
            {
                string _class = "";
                if (i % 2 == 0)
                    _class = " class=\"bgGray\"";
                sb.AppendFormat("  <tr {0}>", _class);
                sb.AppendFormat("	<td><a href=\"Dp{1}.shtml\">{0}</a></td>", list[i].scmc, list[i].code);
                sb.AppendFormat("	<td><span class=\"green\">{0}</span></td>", OTO.PerRedGre(list[i].P, list[i].F, 1, 2, "-", ""));
                sb.AppendFormat("	<td>{0}</td>", OTO.PerRedGre(list[i].F, 2, "-", "%"));
                sb.AppendFormat("	<td>{0}</td>", OTO.PerRedGre(list[i].J, 100000000, 2, "-", ""));
                sb.AppendFormat("	<td>{0}</td>", list[i].gpCount);
                sb.AppendFormat("	<td>{0}/{1}</td>", list[i].uCount, list[i].dCount);
                sb.AppendFormat("	<td class=\"{1}\" align=\"center\" title=\"{2}\">{0}</td>", Math.Abs(list[i].NC), list[i].NC > 0 ? "bg_tipR" : "bg_tipG", Pub.NcTip(list[i].NC));
                sb.AppendLine("  </tr>");
            }
            sb.AppendLine("</table>");
        }
        catch { }
        return sb;
    }

    protected string str操盘摘要(string code)
    {
        string rel = "";
        try
        {
            rel =Pub.LoadData(jsonUrl + "hangqing/cpgy.ashx?bkid=" + code);
        }
        catch { }
        return rel;
    }

    protected StringBuilder sb行业新闻(string code)
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            List<NewsEnty> list = JsonConvert.DeserializeObject<List<NewsEnty>>(Pub.LoadData(jsonUrl + "news/IndustryResearch2.ashx?bkid=" + code));
            sb.AppendLine("<ul>");
            int len = 10;
            if (list.Count < len)
                len = list.Count;
            for (int i = 0; i < len; i++)
            {
                sb.AppendFormat(" <li>·<a href=\"{0}\" target=\"_blank\">{1}</a></li>", GetNewsUrl("12", "0304", list[i].Id), list[i].Title);
            }
            sb.AppendLine("</ul>");
        }
        catch { }
        return sb;
    }

    protected StringBuilder sb行业研究(string code)
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            List<NewsEnty> list = JsonConvert.DeserializeObject<List<NewsEnty>>(Pub.LoadData(jsonUrl + "bkRelateNews2.ashx?bkid=" + code));
            sb.AppendLine("<ul>");
            int len = 10;
            if (list.Count < len)
                len = list.Count;
            for (int i = 0; i < len; i++)
            {
                sb.AppendFormat(" <li>·<a href=\"{0}\" target=\"_blank\">{1}</a></li>", GetNewsUrl("12", "0304", list[i].Id), list[i].Title);
            }
            sb.AppendLine("</ul>");
        }
        catch { }
        return sb;
    }

    protected StringBuilder sb指标分析(string code)
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            BkzbEnty obj = JsonConvert.DeserializeObject<BkzbEnty>(Pub.LoadData(jsonUrl + "hangqing/zdjp.ashx?bkid=" + code));
            sb.AppendLine("<ul>");
            if (obj != null)
            {
                sb.AppendFormat("<li><span class=\"white\">趋势状态</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{0}</li>", obj.trend_state);
                sb.AppendFormat("<li><span class=\"white\">相对强弱</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{0}</li>", obj.strong_weak);
                sb.AppendFormat("<li><span class=\"white\">成交能量</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{0}</li>", obj.match_energy);
                sb.AppendFormat("<li class=\"cur\"><span class=\"white\">资金流向</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{0}</li>", obj.capital_flow);
            }
            else
            {
                sb.AppendLine("<li><span class=\"white\">趋势状态</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li>");
                sb.AppendLine("<li><span class=\"white\">相对强弱</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li>");
                sb.AppendLine("<li><span class=\"white\">成交能量</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;；</li>");
                sb.AppendLine("<li class=\"cur\"><span class=\"white\">资金流向</span>&nbsp;&nbsp;&nbsp;&nbsp;</li>");
            }
            sb.AppendLine("</ul>");
        }
        catch { }
        return sb;
    }


}